package com.demo.controller;

import com.demo.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


/**
 * @author Stone
 * @date 2020/6/15 16:01
 */
@RestController
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/consumer/get/employee")
    public Employee getEmployeeRemote(){
        // 远程调用主机的地址
        // String host = "http://localhost:1000";
        // 采用了eureka后，消费者应该从注册中心拿接口
        // 生产者在eureka注册的名字，就是demo-provider
         String host = "http://demo-provider";
        // 远程调用的url
         String url = "/provider/get/employee/remote";

        return restTemplate.getForObject(host+url, Employee.class);
    }


}
